package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.results.R;
import com.atguigu.srb.core.pojo.vo.BorrowInfoApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowInfoDetailVo;
import com.atguigu.srb.core.pojo.vo.BorrowerInfoVo;
import com.atguigu.srb.core.service.BorrowInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/admin/core/borrowInfo")
public class AdminBorrowInfoController {
    @Autowired
    BorrowInfoService borrowInfoService;

    @ApiOperation("根据借款信息id更新借款信息状态/创建标的")
    @PostMapping("borrowInfoApproval")
    public R borrowInfoApproval(@RequestBody BorrowInfoApprovalVO vo){
        borrowInfoService.borrowInfoApproval(vo);
        return R.success().message("审批成功");
    }
    //根据BorrowInfo的id查询借款详情数据
    @ApiOperation("根据BorrowInfo的id查询借款详情数据")
    @GetMapping("getBorrowInfoDetailVo/{id}")
    public R getBorrowInfoDetailVo(@PathVariable("id")String id){
        BorrowInfoDetailVo borrowInfoDetailVo = borrowInfoService.getBorrowInfoDetailVo(id);
        return R.success().data("item",borrowInfoDetailVo);
    }
    //自定义带条件分页查询的sql： 自己在mapper映射文件中写sql
    @ApiOperation("分页查询借款列表")
    @GetMapping("list/{pageNum}/{pageSize}")
    public R listPage(@PathVariable("pageNum")Integer pageNum,
                      @PathVariable("pageSize")Integer pageSize,
                      String key){
        Page<BorrowerInfoVo> page = new Page<>(pageNum, pageSize);
        borrowInfoService.listPage(page , key);
        return R.success().data("page",page);
    }
}

